<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
      <el-form-item label="审核状态:" prop="auditStatus">
        <el-select v-model="queryParams.auditStatus" placeholder="请选择审核状态" size="mini">
          <el-option
            v-for="dict in dict.type.vip_apply_audit_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="申请时间:">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          format="yyyy-MM-dd"
          value-format="timestamp"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']"
          size="mini"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="序号" type="index" align="center" min-width="5%"/>
      <el-table-column label="用户编号" align="center" prop="uid" key="uid">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="goMemberDetail(scope.row)"
          >
            用户信息
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="邮箱" align="center" prop="email" key="email"/>
      <el-table-column label="昵称" align="center" prop="nickname" key="nickname"/>
      <el-table-column label="头像" align="center" key="avatar">
        <template slot-scope="scope">
          <image-preview class="list-img" :src="scope.row.avatar"/>
        </template>
      </el-table-column>
      <el-table-column label="申请时间" align="center" prop="createTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="auditStatus" key="auditStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.vip_apply_audit_status" :value="scope.row.auditStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="审核人" align="center" prop="auditUserName" key="auditUserName"/>
      <el-table-column label="审核时间" align="center" prop="auditTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.auditTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="驳回理由" align="center" prop="failRemark" key="failRemark"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.auditStatus === '0'"
            size="mini"
            type="text"
            @click="handleEdit(scope.row,'1')"
            v-hasPermi="['system:memberUser:auditVipApply']"
          >通过</el-button>
          <el-button
            v-if="scope.row.auditStatus === '0'"
            size="mini"
            type="text"
            @click="handleEdit(scope.row,'2')"
            v-hasPermi="['system:memberUser:auditVipApply']"
          >驳回</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <member-detail ref="member-detail"/>
  </div>
</template>
<script>
import { vipApplyPageList,auditVipApply } from '@/api/triones/interlaceMember'
import memberDetail from "@/views/triones/member/memberUser/memberDetail.vue";
export default {
  name: "index",
  dicts: ['vip_apply_audit_status'],
  components: {memberDetail },
  data() {
    return {
      loading: false,
      showSearch: true,
      dateRange: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        auditStatus: undefined,
      },
      dataList: [],
      total: 0
    }
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      this.addDateRange(this.queryParams, this.dateRange);
      vipApplyPageList(this.queryParams).then(res => {
        this.dataList = res.rows;
        this.total = res.total;
        this.loading = false;
      })
    },
    /** 检索 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    goMemberDetail(row) {
      this.$refs["member-detail"].show(row.uid);
    },
    /** vip申请审核 */
    handleEdit(row, status) {
      if (status === '2') {
        this.reject(row);
      } else {
        const data = {
          id: row.id,
          auditStatus: status
        }
        this.$modal.confirm('是否确认邮箱为"' + row.email + '"的白标用户申请审核通过？').then(() => {
          this.loading = true;
          return auditVipApply(data);
        }).then(() => {
          this.loading = false;
          this.getList();
          this.$modal.msgSuccess("审核成功！");
        }).finally(() => {
          this.loading = false;
        });
      }
    },
    /** 驳回 */
    reject(row) {
      const data = {
        id: row.id,
        auditStatus: '2',
        failRemark: ''
      }
      this.$prompt('请输入驳回原因', '驳回申请', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
      }).then(({ value }) => {
        data.failRemark = value;
        auditVipApply(data).then(response => {
          this.$message("操作成功");
          this.getList();
        })
      })
    }
  }
}
</script>

<style scoped lang="scss">

</style>
